#ifndef CAMERA_H
#define CAMERA_H
#include<QVector3D>
#include<ray.h>
#include<utils.h>
class camera
{
public:
    //aspect 宽高比
    camera(QVector3D lookfrom,QVector3D lookat,QVector3D vup, float vfov,float aspect,float aperture,float focus_dist,float t0,float t1){
        time0=t0;
        time1=t1;
        lens_radius=aperture/2;
        float theta=vfov*MY_PI/180;
        float half_height=tan(theta/2);
        float half_width=aspect*half_height;
        origin=lookfrom;
        w=(lookfrom-lookat).normalized();
        u=QVector3D::crossProduct(vup,w);
        v=QVector3D::crossProduct(w,u);
//        lower_left_corner=QVector3D(-half_width,-half_height,-1.0);
        lower_left_corner=origin-half_width*focus_dist*u-half_height*focus_dist*v-w*focus_dist;
        horizontal=2*half_width*u*focus_dist;
        vertical=2*half_height*v*focus_dist;

    }
    QVector3D lower_left_corner;
    QVector3D horizontal;
    QVector3D vertical;
    QVector3D origin;
    QVector3D u,v,w;
    float time0,time1;
    float lens_radius;
    ray get_ray(float s,float t)
    {
        QVector3D rd=lens_radius*random_in_unit_disk();
        QVector3D offset=u*rd.x()+v*rd.y();
        float time=time0+Random::get(0.0,0.99)*(time1
                                              -time0);
        return ray(origin+offset,lower_left_corner+s*horizontal+t*vertical-origin-offset,time);
    }
};

#endif // CAMERA_H
